/*	BuildSCV class definition.
 *
*/

#include "BuildSCV.h"

void BuildSCV::Enter()
{
	DEBUG_PRINT("BuildSCV(%p) %s entering\n", this, GetName().c_str());

}

void BuildSCV::Execute()
{
	DEBUG_PRINT("BuildSCV(%p) %s executing\n", this, GetName().c_str());
	std::list<Base*>* bases = BB->GetBases();
	BWAPI::Unit* cc;
	for(std::list<Base*>::iterator base = bases->begin(); base != bases->end(); base++)
	{
		cc = (*base)->GetCC();
		if((*base)->NeedMoreWorkers() && !cc->isTraining() )
		{			
			cc->train(BWAPI::UnitTypes::Terran_SCV);
			BB->SpendResources(BWAPI::UnitTypes::Terran_SCV);	
		}
	}
	control->FinishWithSuccess();
}

void BuildSCV::Exit()
{
	DEBUG_PRINT("BuildSCV(%p) %s exiting\n", this, GetName().c_str());

}

bool BuildSCV::CheckConditions()
{
	DEBUG_PRINT("BuildSCV(%p) %s checking conditions\n", this, GetName().c_str());
	if(BB->isBuildUnit(BWAPI::UnitTypes::Terran_SCV))
	{
		DEBUG_PRINT("BuildSCV(%p) %s checked conditions and has %d minerals to spend\n", this, GetName().c_str(), BB->GetMineralsToSpend());
		return true;
	}
	return false;
}